package file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2025-03-04
 * Time: 20:40
 */
// inputStream的使用
public class Demo7 {
    public static void main(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("c:/code/test.txt")) {
            while (true) {
                byte[] buf = new byte[1024];
                int n = inputStream.read(buf);
                if (n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%x ", buf[i]);
                }
                String s = new String(buf, 0, n, "utf8");
                System.out.println(s);
            }
        }
    }
}
